package com.pubinfo.passbook.api.controller.contract;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.pubinfo.passbook.api.eip.UserInfoService;
import com.pubinfo.passbook.common.model.bo.witeoff.ContractWiteoffBase;
import com.pubinfo.passbook.common.model.dto.contract.*;
import com.pubinfo.passbook.common.model.vo.base.JsonResult;
import com.pubinfo.passbook.common.model.vo.contract.*;
import com.pubinfo.passbook.common.service.contract.*;
import com.pubinfo.passbook.common.service.mss.CostWriteOffService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.dom4j.DocumentException;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;

@Slf4j
@RestController
@Api(tags = "QGPB-收益管理(冲销)")
@RequestMapping(value = "profit")
public class CostWriteOffController {

    @Resource
    private TContractProjectCostItemsService tContractProjectCostItemsService;

    @Resource
    private TContractBaseService contractBaseService;

    @Resource
    private TContractPaymentItemsService tContractPaymentItemsService;

    @Resource
    private TContractWriteoffRelationService contractWriteoffRelationService;


    @Resource
    private CostWriteOffService costWriteOffService;

    @Resource
    private TContractWriteoffHeaderService tContractWriteoffHeaderService;

    @Resource
    private UserInfoService userInfoService;

    @PostMapping("list")
    @ApiOperation(value = "查询列表数据")
    public JsonResult<IPage<FeeCollectionListVo>> list(@RequestBody FeeListParam feeListParam) {

        return JsonResult.success(tContractPaymentItemsService.getFeeList(feeListParam));
    }

    @PostMapping("detail")
    @ApiOperation(value = "合同详情")
    public JsonResult<ContractDetailVo> detail(@RequestBody ContractIdParam param) {
        return JsonResult.success(contractBaseService.contractDetail(param));
    }

    @PostMapping("incomeList")
    @ApiOperation(value = "收入挑对")
    public JsonResult<List<IncomeInfoVo>> incomeList(@RequestBody ContractIdParam param) {
        //通过合同号查询收入挑对信息
        return contractWriteoffRelationService.incomeList(param);
    }

    @PostMapping("writeOff")
    @ApiOperation(value = "可冲销WBS成本信息")
    public JsonResult<List<TContractProjectCostItemsVo>> WriteOff(@RequestBody ContractIdParam param) {
        return JsonResult.success(tContractProjectCostItemsService.getProjectCostList(param));
    }

    @PostMapping("reimbursemenManagement")
    @ApiOperation(value = "报账管理")
    public JsonResult<IPage<WriteOffRollbackVo>> reimbursemenManagement(@RequestBody WriteOffBackParam param) {

        return JsonResult.success(tContractWriteoffHeaderService.getReimbursemenList(param));

    }

    @GetMapping("compensateList")
    @ApiOperation(value = "生成报账单")
    public JsonResult<CompensateBaseVo> compensateList(Integer type) {
        //返回前端报账单所需数据
        return contractWriteoffRelationService.costWriteOffList(type, userInfoService.getCurrentAcct());
    }

    @PostMapping("confirm")
    @ApiOperation(value = "生成报账单-成本冲销")
    public JsonResult<String> confirm(@RequestBody ContractWiteoffBase dto) throws DocumentException {

        return costWriteOffService.reimbursementForm(dto, true);

    }

    @PostMapping("confirmOrBack")
    @ApiOperation(value = "生成报账单-冲成本冲销")
    public JsonResult<String> confirmOrBack(@RequestBody ContractWiteoffBase dto) throws DocumentException {

        return costWriteOffService.reimbursementForm(dto, true);

    }
    @PostMapping("witeOffBackList")
    @ApiOperation(value = "冲冲销-收入挑对数据")
    public JsonResult<List<IncomeInfoBackVo>> witeOffBackList(@RequestBody BackParam code){

        return JsonResult.success(contractWriteoffRelationService.IncomeInfoBackList(code));

    }
    @PostMapping("wbsBackList")
    @ApiOperation(value = "冲冲销-WBS挑对数据")
    public JsonResult<List<TContractProjectCostItemsBackVo>> wbsBackList(@RequestBody WBackParam param){

        return JsonResult.success(contractWriteoffRelationService.WBSInfoBackList(param));

    }


}
